.\" Copyright (c) 2002-2018 Julien Nadeau Carriere <vedge@csoft.net>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 19, 2003
.Dt AG_COMBO 3
.Os
.ds vT Agar API Reference
.ds oS Agar 1.0
.Sh NAME
.Nm AG_Combo
.Nd agar canned text input + drop-down menu widget
.Sh SYNOPSIS
.Bd -literal
#include <agar/core.h>
#include <agar/gui.h>
.Ed
.Sh DESCRIPTION
.\" IMAGE(http://libagar.org/widgets/AG_ComboExpanded.png, "Expanded AG_Combo(3) widget")
.\" IMAGE(http://libagar.org/widgets/AG_Combo.png, "Collapsed AG_Combo(3) widget")
The
.Nm
widget packs a
.Xr AG_Textbox 3
widget left to a
.Xr AG_Button 3 ,
which causes a
.Xr AG_Tlist 3
to popup when pressed.
The tlist disappears when an option is selected.
.Sh INHERITANCE HIERARCHY
.Xr AG_Object 3 ->
.Xr AG_Widget 3 ->
.Nm .
.Sh INITIALIZATION
.nr nS 1
.Ft "AG_Combo *"
.Fn AG_ComboNew "AG_Widget *parent" "Uint flags" "const char *format" "..."
.Pp
.Ft "AG_Combo *"
.Fn AG_ComboNewS "AG_Widget *parent" "Uint flags" "const char *label"
.Pp
.Ft "void"
.Fn AG_ComboSizeHint "AG_Combo *combo" "const char *text" "int nitems"
.Pp
.Ft "void"
.Fn AG_ComboSizeHintPixels "AG_Combo *combo" "int w" "int nitems"
.Pp
.nr nS 0
The
.Fn AG_ComboNew
function allocates, initializes, and attaches a new
.Nm
widget.
The string argument specifies an optional text label to be displayed at the
left of the textbox.
Acceptable
.Fa flags
include:
.Bl -tag -width "AG_COMBO_SCROLLTOSEL "
.It AG_COMBO_POLL
List contents are dynamic (pass the
.Dv AG_TLIST_POLL
flag to the
.Va tlist ) .
.It AG_COMBO_ANY_TEXT
Allow user to enter text that does not match any item in the list.
.It AG_COMBO_SCROLLTOSEL
Scroll to initial selection if it is not visible.
.It AG_COMBO_HFILL
Expand horizontally in parent container.
.It AG_COMBO_VFILL
Expand vertically in parent container.
.It AG_COMBO_EXPAND
Shorthand for
.Dv AG_COMBO_HFILL | AG_COMBO_VFILL .
.El
.Pp
The
.Fn AG_ComboSizeHint
function arranges for the
.Xr AG_Tlist 3
widget displayed on popup to request a size large enough to display the given
number of items.
The
.Fn AG_ComboSizeHintPixels
variant specifies the width in number of pixels.
.Sh ITEM SELECTION
.nr nS 1
.Ft void
.Fn AG_ComboSelect "AG_Combo *combo" "AG_TlistItem *item"
.Pp
.Ft "AG_TlistItem *"
.Fn AG_ComboSelectPointer "AG_Combo *combo" "void *ptr"
.Pp
.Ft "AG_TlistItem *"
.Fn AG_ComboSelectText "AG_Combo *combo" "const char *text"
.Pp
.nr nS 0
The
.Fn AG_ComboSelect
function sets the selection flag on the given
.Fa item .
.Pp
The
.Fn AG_ComboSelectPointer
function selects the first item with a user pointer value matching
.Fa ptr .
Similarly,
.Fn AG_ComboSelectText
selects the first item with a text string equal to
.Fa text .
.Pp
If the
.Dv AG_COMBO_POLL
option is set, both
.Fn AG_ComboSelectPointer
and
.Fn AG_ComboSelectText
will raise a
.Sq tlist-poll
event prior to making the selection.
.Sh EVENTS
The
.Nm
widget generates the following events:
.Pp
.Bl -tag -compact -width 2n
.It Fn combo-selected "AG_TlistItem *item"
An item was selected.
.It Fn combo-text-entry "const char *text"
The
.Dv AG_COMBO_ANY_TEXT
option is set and the user has entered a string
.Fa text
which does not match any item in the list.
.It Fn combo-text-unknown "const char *text"
The
.Dv AG_COMBO_ANY_TEXT
flag is not set and the user has entered a string
.Fa text
which does not match any item in the list.
.El
.Sh STRUCTURE DATA
For the
.Ft AG_Combo
object:
.Pp
.Bl -tag -compact -width "AG_Textbox *tbox "
.It Ft AG_Tlist *list
Pointer to the
.Xr AG_Tlist 3
displayed by
.Nm
when expanded (read-only).
.It Ft AG_Textbox *tbox
Pointer to the
.Xr AG_Textbox 3
contained in the
.Nm
(read-only).
.It Ft AG_Button *button
Pointer to the
.Xr AG_Button 3
next to the textbox (read-only).
.El
.Sh EXAMPLES
The following code fragment reacts to a
.Nm
selection event by displaying a text dialog:
.Bd -literal -offset indent
void
Selected(AG_Event *event)
{
	AG_TlistItem *item = AG_TLIST_ITEM_PTR(1);
	
	AG_TextMsg(AG_MSG_INFO, "Selected item: %s", item->text);
}

AG_Combo *com = AG_ComboNew(NULL, 0, "Item: ");
AG_TlistAdd(com->list, NULL, "Foo");
AG_TlistAdd(com->list, NULL, "Bar");
AG_SetEvent(com, "combo-selected", Selected, NULL);
.Ed
.Sh SEE ALSO
.Xr AG_Button 3 ,
.Xr AG_Intro 3 ,
.Xr AG_Textbox 3 ,
.Xr AG_Tlist 3 ,
.Xr AG_Widget 3 ,
.Xr AG_Window 3
.Sh HISTORY
The
.Nm
widget first appeared in Agar 1.0.
As of Agar 1.6.0,
.Dv AG_COMBO_TREE
is a deprecated no-op.
